package br.unb.mestrado.simulator.model.spl;

import java.util.ArrayList;
import java.util.List;

public abstract class Feature implements FeatureInterface{

	protected Long id;
	protected String name;
	protected List<Feature> features;
	protected Boolean enabled;

	protected boolean abstractFeature = false;
	protected boolean mandatory = false;

	public Feature(String name) {
		this.name = name;
		this.features = new ArrayList<Feature>();
	}
	
	public Feature(String name, Boolean enabled) {
		this(name);
		this.enabled = enabled;
	}
	
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Override
	public final Boolean getEnabled() {
		return enabled;
	}
	@Override
	public final void setEnabled(Boolean enabled) {
		this.enabled = enabled;
	}
	
	public void addFeature(Feature feature){
		this.features.add(feature);
	}
	
	public List<Feature> getFeatures() {
		return features;
	}
	

	public boolean hasChildren() {
		if(features==null || features.isEmpty()){
			return false;
		}
		return true;
	}

	public final String getName() {
		return name;
	}

	

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof Feature))
			return false;
		Feature other = (Feature) obj;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}

	public void onDestroy() {
		if(this.features!=null){
			for (Feature feature : features) {
				feature.onDestroy();
			}
			this.features.clear();
		}
	}
}
